﻿using System.Linq;
using System.Web;
using Concret;

public class Register : HandlerBase
{
	/// <summary>
	/// 登录
	/// </summary>
	/// <param name="acc"></param>
	/// <param name="psw"></param>
	/// <param name="name"></param>
	/// <returns></returns>
	[NoLogin]
	public dynamic register(string acc, string psw, string name)
	{
		var user = new Users(DbOp) { Account_Val = acc }.GetByFVs().SingleOrDefault();
		if (user != null) throw new Error("用户已存在，请去登录");

		if (new Users(DbOp) { Account_Val = acc, Password_Val = psw, Uname_Val = name }.Insert().HasValue)
		{
			Response.Cookies.Add(new HttpCookie("acc", acc));
			Response.Cookies.Add(new HttpCookie("psw", psw));
		}
		else
			throw new Error("注册失败，请重新尝试");

		return null;
	}
}